//
//  YDRechargeTableFooterView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDRechargeTableFooterView.h"

@interface YDRechargeTableFooterView()<UIWebViewDelegate>
@property (nonatomic , weak) UIView *addBankBackView;
@property (nonatomic , weak) UIImageView *addBnakImage;
////温馨提示
//@property (nonatomic , weak) UILabel *postLabel;
////内容
//@property (nonatomic , weak) UILabel *detailLabel;

@property (nonatomic, strong)UIWebView *tipsWebview;
@end



@implementation YDRechargeTableFooterView


+ (instancetype)footerViewWithTableView:(UITableView *)tableView
{
    
    static NSString *rechargeTableFooterView = @"YDRechargeTableFooterView";
    YDRechargeTableFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:rechargeTableFooterView];
    if (footerView == nil) {
        footerView = [[YDRechargeTableFooterView alloc] initWithReuseIdentifier:rechargeTableFooterView];
    }
    return footerView;
}


-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor clearColor];
        [self addBankBackView];
        [self addBnakImage];
        [self tipsWebview];
//        [self postLabel];
//
//        [self detailLabel];
        
    }
    return self;
}
-(UIView *)addBankBackView
{
    if (_addBankBackView == nil) {
        UIView *addBankBackView = [[UIView alloc] init];
        [self.contentView addSubview:addBankBackView];
        addBankBackView.userInteractionEnabled = YES;
        addBankBackView.backgroundColor = [UIColor clearColor];
        
        [addBankBackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.left.right.equalTo(self);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(25)));
                make.top.equalTo(self).offset(rateX812(10));
            }else{
                make.height.equalTo(@(rate750(25)));
                make.top.equalTo(self).offset(rate750(10));
            }
            
        }];
        
        _addBankBackView = addBankBackView;
    }
    return _addBankBackView;
}
//mine-tianjia
-(UIImageView *)addBnakImage
{
    if (_addBnakImage == nil) {
        UIImageView *addBnakImage = [[UIImageView alloc] init];
        [self.addBankBackView addSubview:addBnakImage];
        addBnakImage.image = [UIImage imageNamed:@"mine-tianjia"];
        [addBnakImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.addBankBackView);
        }];
        addBnakImage.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
        [addBnakImage addGestureRecognizer:tap];
        _addBnakImage = addBnakImage;
    }
    return _addBnakImage;
}
-(void)tapClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(rechargeTableFooterViewDidClickAddButton:)]) {
        [self.delegate rechargeTableFooterViewDidClickAddButton:self];
    }
}
//-(UILabel *)postLabel
//{
//    if (_postLabel == nil) {
//        UILabel *postLabel = [[UILabel alloc] init];
//        [self.contentView addSubview:postLabel];//blueyGrey
//        postLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
//        postLabel.textColor = [UIColor colorWithHexString:blueyGrey];
//        postLabel.textAlignment = NSTextAlignmentLeft;
//        postLabel.text = @"温馨提示";
//        [postLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self).offset(rate375(20));
//            if (isPhoneX) {
//                make.top.equalTo(self.addBankBackView.mas_bottom).offset(rateX812(10));
//            }else{
//                make.top.equalTo(self.addBankBackView.mas_bottom).offset(rate750(10));
//            }
//        }];
//        _postLabel = postLabel;
//    }
//    return _postLabel;
//}

//-(UILabel *)detailLabel
//{
//    if (_detailLabel == nil) {
//        UILabel *detailLabel = [[UILabel alloc] init];
//        [self.contentView addSubview:detailLabel];//blueyGrey
//        detailLabel.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
//        detailLabel.textColor = [UIColor colorWithHexString:paleRed];
//        detailLabel.textAlignment = NSTextAlignmentLeft;
//        detailLabel.numberOfLines = 0;
//        [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.postLabel);
//            make.right.equalTo(self).offset(-rate375(20));
//            if (isPhoneX) {
//                make.top.equalTo(self.postLabel.mas_bottom).offset(rateX812(10));
//            }else{
//                make.top.equalTo(self.postLabel.mas_bottom).offset(rate750(10));
//            }
//        }];
//        NSString *string = @"1、为了您的资金安全，您的账户资金将由第三方银行托管；\n2、充值前请注意您的一行卡充值限额，以免造成不便；\n3、禁止洗钱、信用卡套现、虚假交易等行为，已经发现并确认，将终止该账户的使用；\n4、如果无法充值，请联系客服。";
//
//        NSAttributedString *attr = [NSString createLineWrapAttriStringWithString:string andLineSpace:2.0 withWrapSpace:0.3 Font:[UIFont systemFontOfSize:font12ScreenWRate * LKScreenW]];
//
//        detailLabel.attributedText = attr;
//
//        _detailLabel = detailLabel;
//    }
//    return _detailLabel;
//}
- (void)callPhone
{
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",CustomerPhone];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self callPhone];
        });
        return NO;
    }else
    {
        return YES;
    }
    
}
-(UIWebView *)tipsWebview
{
    if (_tipsWebview == nil) {
        _tipsWebview = [UIWebView new];
        _tipsWebview.scrollView.scrollEnabled = NO;
        _tipsWebview.delegate = self;
        _tipsWebview.userInteractionEnabled = YES;
        [self.contentView addSubview:_tipsWebview];
        _tipsWebview.backgroundColor = [UIColor colorWithHexString:mainGray];
        [_tipsWebview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            
            if (isPhoneX) {
                make.top.equalTo(self.addBankBackView.mas_bottom).offset(rateX812(19));
            }else{
                make.top.equalTo(self.addBankBackView.mas_bottom).offset(rate750(19));
            }
            make.height.equalTo(@200);
        }];
        [_tipsWebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"WarmTips" ofType:@".html" ]]]];
        
    }
    return _tipsWebview;
}

@end
